//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.周赛.周赛446;

import java.util.HashSet;

public class demo_Q1 {
    public demo_Q1() {
    }

    public static void main(String[] args) {
        String[] instructions = new String[]{"add"};
        int[] values = new int[]{0};
        System.out.println(calculateScore(instructions, values));
    }

    public static long calculateScore(String[] instructions, int[] values) {
        HashSet<Integer> set = new HashSet();
        long count = 0L;
        int index = 0;
        int n = instructions.length;

        while(index >= 0 && index < n && !set.contains(index)) {
            set.add(index);
            if (instructions[index].equals("add")) {
                count += (long)values[index];
                ++index;
            } else {
                index += values[index];
            }
        }

        return count;
    }
}
